<?php
class IndexApp extends CommonApp {
   
    public function indexAct(){
    	//轮播图
    	$carousel = My::alias2detail('config','home');
    	$this->assign('carousel',$carousel['params']['image']);

    	//最新揭晓
    	$result['rate'] = DB('goods')->where("publish = '1'")->order("rate DESC")->limit(4)->clear()->select();
    	foreach($result['rate'] as &$value){
    		$value['params'] = My::decodeJson($value['params']);
    	}
    	//新品推荐
    	$result['new'] = DB('goods')->where("publish = '1' AND hot = '1'")->order("adddate ASC")->limit(3)->clear()->select();
    	foreach($result['new'] as &$value){
    		$value['params'] = My::decodeJson($value['params']);
    	}
    	//猜你喜欢
    	$result['love'] = DB('goods')->where("publish = '1' OR hot = '1'")->order("adddate ASC")->clear()->limit(0,6)->select();
    	foreach($result['love'] as &$value){
    		$value['params'] = My::decodeJson($value['params']);
    	}
    	//display
    	$this->assign('result',$result);
		$this->display();
    }

    public function moreAct(){
        $page = My::arr2var($_GET,'page');
        //猜你喜欢
        $result = DB('goods')->where("publish = '1' OR hot = '1'")->order("adddate ASC")->clear()->limit(($page-1)*6,6)->select();
        $html = '';
        if($result){
            foreach ($result as &$value) {
                $value['image'] = !empty($value['image']) ? My::thums($value['image'],400,400,true) : My::thums('share/images/default.jpg',400,400,true);
                $value['params'] = My::decodeJson($value['params']);
                $final = $value['number']-$value['partake'];
                $html .= <<<HTML
                    <li class="i_li">
                        <a href="index.php?app=Goods&act=detail&id={$value['id']}">
                            <div class="img_inner">
                                <img src="{$value['image']}">
                            </div>
                            <p class="i_txt">{$value['title']}</p>
                        </a>
                        <div class="cont">
                            <div class="bom">
                                <a onclick="addcart({$value['id']})"><div class="cart"></div></a>
                                <a href="javascript:" class="buybtn">立即一元运购</a>
                            </div>
                        </div>
                    </li>
HTML;
            }
            $html = Router::getInstance()->encodeUrls($html);
            $this->ajaxReturn('200',$html);
        }else $this->ajaxReturn('300','没有更多数据了...');
        
    }
   
}